package protocol.JT808_2011;

import java.util.HashMap;

public class Handle808_2011JT00 implements IHandle808_2011JT {

    @Override
    public String handle(JT808_2011Cmd cmd) {
        byte subOrder = cmd.subOrder();

        switch (subOrder){
            case 0x01:
                return handle0001(cmd);
            case 0x02:
                return handle0002(cmd);
            case 0x03:
                return handle0003(cmd);
            default:
                return "808-2011:未匹配的命令字"+(cmd.readOrder()+","+cmd.subOrder());
        }
    }

    private String handle0003(JT808_2011Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:终端注销");
        builder.append("\r\n");
        return builder.toString();
    }

    private String handle0001(JT808_2011Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:终端通用应答");
        builder.append("\r\n");
        builder.append("应答流水号："+cmd.readBCD(2));
        builder.append("\r\n");
        builder.append("应答ID："+cmd.readBCD(2));
        builder.append("\r\n");

        int res = cmd.readInt(1);
        HashMap<Integer,String> list = new HashMap<>();
        list.put(0,"成功/确认");
        list.put(1,"失败");
        list.put(2,"消息有误");
        list.put(3,"不支持");

        builder.append("结果："+list.getOrDefault(res,"未定义"));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle0002(JT808_2011Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:心跳");
        builder.append("\r\n");

        return builder.toString();
    }
}
